package hihocoder;
import java.util.Scanner;

/**
 * 
 */

/**
 * @author zhongfang
 *
 */
public class 数组重排22 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		int N=scanner.nextInt();
		int[] A=new int[N];
		for (int i = 0; i < N; i++) {
			A[i]=scanner.nextInt()-1;
		}
		int n=getResult(A);
	}

	private static int getResult(int[] a) {
		int min=Integer.MAX_VALUE;
		for (int i = 1; i < a.length; i++) {
			int[] tmpAry=new int[a.length];
			tmpAry[0]=a[i];
			int j = 1;
			for (; j <= i; j++) {
				tmpAry[j]=a[j-1];
			}
			for (; j <a.length; j++) {
				tmpAry[j]=a[j];
			}
			int x=getResult(tmpAry);
			if(min>x){
				min=x;
			}
		}
		return min+1;
	}
}
